package com.css.fxfzxczh.modules.samplingPointDataCensus.classifiedStatistics.service.impl;

import com.css.fxfzxczh.constants.XczhConstants;
import com.css.fxfzxczh.modules.disasterSituationDataManage.samPoiHouSur.entity.HouDamSta;
import com.css.fxfzxczh.modules.disasterSituationDataManage.samPoiHouSur.repository.HouDamStaRepository;
import com.css.fxfzxczh.modules.disasterSituationDataManage.samPoiHouSur.vo.HouDamStaVo;
import com.css.fxfzxczh.modules.samplingPointDataCensus.classifiedStatistics.repository.ClassifiedStatisticsRepository;
import com.css.fxfzxczh.modules.samplingPointDataCensus.classifiedStatistics.service.ClassifiedStatisticsService;
import com.css.fxfzxczh.modules.samplingPointDataCensus.param.QueryParam;
import com.css.fxfzxczh.modules.synthesizeInfoManage.houseStructureManagement.service.HouseStructureManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:
 * @CreateTime: 2023/6/3 13:53
 * @Description:
 */
@Service
public class ClassifiedStatisticsServiceImpl implements ClassifiedStatisticsService {

    @Autowired
    ClassifiedStatisticsRepository classifiedStatisticsRepository;

    @Autowired
    HouseStructureManagementService houseStructureManagementService;

    @Resource
    HouDamStaRepository houDamStaRepository;


    @Override
    public List<Map<String, Object>> getStructureAreaProportion(QueryParam queryParam) {
       /* List<Map<String, Object>> list=new ArrayList<>();

        //获取结构类型
        List<String> structureList = houseStructureManagementService.getPreStrType("预置");
        //获取合计面积
        HouDamStaVo houDamStaVo = houDamStaRepository.getTotalArea(queryParam);
        //获取符合查询条件的统计数据
        List<HouDamSta> StatisticList=houDamStaRepository.getStatistic(queryParam);

        //循环结构类型
        for(String structure:structureList){
            //获取单个类型面积之和
            Integer num = 0;
            Map<String, Object> map=new HashMap<>();
            for (HouDamSta statistic:StatisticList){
                if(structure.equals(statistic.getStructureType())){
                    num+=Integer.valueOf(statistic.getTotalArea());
                }
            }


            BigDecimal area=new BigDecimal(num);
            //单个类型面积之和 / 总面积之和 = 比率
            BigDecimal proportion = area.divide(new BigDecimal(houDamStaVo.getTotalArea()),4,BigDecimal.ROUND_FLOOR).multiply(new BigDecimal("100"));
            map.put("structure",structure);
            map.put("proportion",proportion);
            map.put("area",area); 
            list.add(map);*/

        List<Map<String, Object>> list=new ArrayList<>();

        //获取结构类型
        List<String> structureList = houseStructureManagementService.getPreStrType("预置");
        //获取符合查询条件的统计数据
        List<HouDamSta> StatisticList=houDamStaRepository.getStatistic(queryParam);

        //循环结构类型
        for(String structure:structureList){
            //获取单个类型面积之和
            Integer num = 0;

            for (HouDamSta statistic:StatisticList){
                if(structure.equals(statistic.getStructureType())){
                    num+=Integer.valueOf(statistic.getTotalArea());
                }
            }

            Map<String, Object> map=new HashMap<>();
            map.put("name",convert(structure));
            map.put("value",num);
            list.add(map);
        }






        return list;
    }

    private String convert(String type) {
        if (XczhConstants.ONE_TYPE.equals(type)) {
            type = "I类";
        }
        if (XczhConstants.TWO_TYPE.equals(type)) {
            type = "II类";
        }
        if (XczhConstants.THREE_ONE_TYPE.equals(type)) {
            type = "III-1类";
        }
        if (XczhConstants.THREE_TWO_TYPE.equals(type)) {
            type = "III-2类";
        }
        if (XczhConstants.FOUR_TYPE.equals(type)) {
            type = "Ⅳ类";
        }
        if (XczhConstants.FIVE_ONE_TYPE.equals(type)) {
            type = "V-1类";
        }
        if (XczhConstants.FIVE_TWO_TYPE.equals(type)) {
            type = "V-2类";
        }
        if (XczhConstants.FIVE_THREE_TYPE.equals(type)) {
            type = "V-3类";
        }
        if (XczhConstants.SIX_TYPE.equals(type)) {
            type = "Ⅵ类";
        }
        if (XczhConstants.SEVEN_TYPE.equals(type)) {
            type = "Ⅶ类";
        }
        return type;
    }


    @Override
    public List<Map<String,Object>> getDamageAreaProportion(QueryParam queryParam) {
        List<Map<String, Object>> list=new ArrayList<>();
        Map<String, Object> destroyMap=new HashMap<>();
        Map<String, Object> seriousDamageMap=new HashMap<>();
        Map<String, Object> moderateDamageMap=new HashMap<>();
        Map<String, Object> minorDamageMap=new HashMap<>();
        Map<String, Object> basicallyIntactMap=new HashMap<>();
        //获取合计面积
        HouDamStaVo houDamStaVo = houDamStaRepository.getTotalArea(queryParam);
        //总面积
        //Integer totalArea = houDamStaVo.getTotalArea();
        //BigDecimal totalAreaBig = new BigDecimal(totalArea);
        //毁坏面积
        destroyMap.put("name","毁坏");
        destroyMap.put("value",houDamStaVo.getDestroyArea()==null?0:houDamStaVo.getDestroyArea());
        //严重破坏面积
        seriousDamageMap.put("name","严重破坏");
        seriousDamageMap.put("value",houDamStaVo.getSeriousDamageArea()==null?0:houDamStaVo.getSeriousDamageArea());
        //中等破坏面积
        moderateDamageMap.put("name","中等破坏");
        moderateDamageMap.put("value",houDamStaVo.getModerateDamageArea()==null?0:houDamStaVo.getModerateDamageArea());
        //轻微破坏面积
        minorDamageMap.put("name","轻微破坏");
        minorDamageMap.put("value",houDamStaVo.getMinorDamageArea()==null?0:houDamStaVo.getMinorDamageArea());
        //基本完好面积
        basicallyIntactMap.put("name","基本完好");
        basicallyIntactMap.put("value",houDamStaVo.getBasicallyIntactArea()==null?0:houDamStaVo.getBasicallyIntactArea());
        list.add(basicallyIntactMap);
        list.add(minorDamageMap);
        list.add(moderateDamageMap);
        list.add(seriousDamageMap);
        list.add(destroyMap);
        return list;
    }
}
